home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9294 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.0 KB  |  82 lines

  1. Newsgroups: comp.lang.modula3,comp.lang.c++,comp.lang.java
  2. Path: beaver.cs.washington.edu!whsieh
  3. From: whsieh@porky-pig.lcs.mit.edu (Wilson Hsieh)
  4. Subject: Re: Java closer to Modula-3 than to C++
  5. Sender: news@beaver.cs.washington.edu (USENET News System)
  6. Organization: Department of Computer Science and Engineering, UW
  7. Message-ID: <WHSIEH.96Feb29123728@porky-pig.lcs.mit.edu>
  8. References: <31308FE2.167E@sophia.inria.fr> <1996Feb26.192508.2614@friend.kastle.com>
  9.     <DAGENAIS.96Feb29113254@hagen.vlsi.polymtl.ca>
  10. In-Reply-To: dagenais@hagen.vlsi.polymtl.ca's message of 29 Feb 96 11:32:54
  11. X-Nntp-Posting-Host: porky-pig.cs.washington.edu
  12. Date: Thu, 29 Feb 1996 20:37:28 GMT
  13.  
  14.  
  15.  
  16.  
  17. We (the SPIN group at UW) have noticed some potential alignment
  18. problems in going between M3 and C.  These problems are very
  19. implementation-dependent, but you probably should be aware of them.
  20. SPIN currently runs DEC SRC M3 on Alphas, but I'm sure similar issues
  21. arise on other platforms.  Take the apparently equivalent types:
  22.  
  23.    struct foo {
  24.      int x:8;
  25.      int y:8;
  26.      int z:8;
  27.    };
  28.  
  29.    TYPE FOO = RECORD
  30.      x: BITS 8 FOR [0..255];
  31.      y: BITS 8 FOR [0..255];
  32.      z: BITS 8 FOR [0..255];
  33.    END
  34.  
  35. The C compilers on the Alpha that we have (DEC cc and gcc), and I
  36. would suspect most C compilers, pad the C structure out to 32 bits.
  37. The DEC SRC M3 compiler does not pad out the RECORD.  There are
  38. several possible sources of problems here in passing a REF FOO type
  39. out to C, which expects a struct foo, which boil down to the fact that
  40. the C compilers assume that a struct foo is 32-bit aligned, whereas a
  41. FOO need not be.  (For example, an ARRAY OF FOO is not the same as a C
  42. array of struct foo!)
  43.  
  44. Also, note that the DEC SRC M3 compiler is not strictly less
  45. restrictive than the C compilers in terms of alignment, so problems
  46. can arise when going from C to M3 as well.  The M3 compiler rounds up
  47. alignment, as long as padding is not required.  (We first noticed
  48. these issues when dealing with trying to VIEW network packet headers,
  49. by the way.)  For example,
  50.  
  51.    struct bar {
  52.      int x:16;
  53.      int y:16;
  54.      int z:16;
  55.      int a:16;
  56.    };
  57.  
  58.    TYPE BAR = RECORD
  59.      x: BITS 16 FOR [0..16_ffff];
  60.      y: BITS 16 FOR [0..16_ffff];
  61.      z: BITS 16 FOR [0..16_ffff];
  62.      a: BITS 16 FOR [0..16_ffff];
  63.    END
  64.  
  65. Our C compilers again assume that a struct bar is 32-bit aligned,
  66. whereas the DEC SRC M3 compiler boosts the alignment of BAR such that
  67. every BAR is 64-bit aligned.
  68.  - Wilson
  69.  
  70.  
  71. In article <DAGENAIS.96Feb29113254@hagen.vlsi.polymtl.ca> dagenais@hagen.vlsi.polymtl.ca (Michel Dagenais) writes:
  72.  
  73.    In article <1996Feb26.192508.2614@friend.kastle.com> rich@kastle.com (Richard Krehbiel) writes:
  74.  
  75.       Oh, I think it's clear that C++ gets it's success from C.  C #includes
  76.       and libraries can (almost always) be called upon in C++ programs.
  77.       Nothing like that can be said of Modula-3 or Java.
  78.  
  79.    Well, too bad i did not know i could not do it. I have called X libraries,
  80.    unix system calls, the gnu dbm library, ODBC drivers... from Modula-3 without
  81.    problem.
  82.